import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/product_bean.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/acom/ui_process_info.dart';
import 'package:app/src/ui/route/works/public/items/ui_process_list.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_product_info.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

///合同审核详情->产品信息
class ProductInfoRoute extends StatefulWidget {
  Product data; //产品信息
  Product? oldData; //历史记录产品信息
  bool isContractoryalty = false; //是否为提成比例审核跳转过来的产品信息
  ProductInfoRoute(this.data, this.oldData, this.isContractoryalty);

  @override
  _State createState() => _State();
}

class _State extends State<ProductInfoRoute> {
  _Presenter? presenter;

  @override
  void initState() {
    super.initState();
    presenter = _Presenter(widget.data, widget.oldData);
  }

  @override
  Widget build(BuildContext context) {
    return AppUi.getScaffold(
        context, _body(context), AppStrings.of(context).ProductInformation);
  }

  Widget _body(BuildContext context) {
    if (presenter?.data == null) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    if (widget.isContractoryalty) {
      ///提成比例审核里的产品信息
      children.add(UiProuctInfo.buildWithTicheng(
          context, presenter?.data, presenter?.oldData)); //产品信息
    } else {
      ///合同审核里的产品信息
      children.add(UiProuctInfo.buildWithProuct(
          context, presenter?.data, presenter?.oldData)); //产品信息
    }
    // children.add(UiNote.build(context, presenter?.data?.StructureContent,
    //     presenter?.oldData?.StructureContent,
    //     title: AppStrings.of(context).ProductNote)); //产品备注；已经写到产品信息里面去了。
    children.add(UiNote.build(
        context, presenter?.data?.FxIntro, presenter?.oldData?.FxIntro,
        title: AppStrings.of(context).FxIntro)); //分箱备注
    children.add(UiNote.build(
        context, presenter?.data?.ZlIntro, presenter?.oldData?.ZlIntro,
        title: AppStrings.of(context).ZlIntro)); //质量备注
    children.add(UiNote.build(
        context, presenter?.data?.JsIntro, presenter?.oldData?.JsIntro,
        title: AppStrings.of(context).JsIntro)); //技术备注
    children.add(UiNote.build(context, presenter?.data?.OrderContent,
        presenter?.oldData?.OrderContent,
        title: AppStrings.of(context).OrderContent)); //其他备注
    children.add(
        UiProcessList.build(context, presenter?.data.getProcessList())); //工艺路线
    var processList = presenter?.data?.ProcessInfoList;
    if (processList != null) {
      if (processList.length == 1) {
        var element = processList[0];
        children.add(UiProcessInfo.build(context, element, false,
            title: AppStrings.of(context).ProductStructureLayerInfo)); //工艺信息
      } else {
        var index = 1;
        processList?.forEach((element) {
          children.add(UiProcessInfo.build(context, element, false,
              title: AppStrings.of(context).ProcessList +
                  index.toString())); //工艺路线
          index++;
        });
      }
    }
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
      ],
    );
  }
}

class _Presenter {
  Product data; //产品信息
  Product? oldData;

  _Presenter(this.data, this.oldData); //历史记录产品信息
}
